﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using System.Data;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.UserManagement.RolMgr
{
    public partial class RolMgrUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (ApplicationProxy appProxy = new ApplicationProxy())
                {
                    ApplicationDataSet.T_ApplicationDataTable appDT2 = appProxy.GetApplicationByType("BasicApp", null);
                    this.dlExtApps.DataSource = appDT2;
                    this.dlExtApps.DataBind();
                }
            }
        }

        protected void dlExtApps_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                HtmlAnchor link = (HtmlAnchor)e.Item.FindControl("linkExtApp");
                LinkButton lbMyApp = (LinkButton)e.Item.FindControl("lbExtApp");
                Label lblId = (Label)e.Item.FindControl("lblId");
                SetLinkURL(link, lbMyApp, drv,lblId);
            }
        }

        private void SetLinkURL(HtmlAnchor link, LinkButton linkApp, DataRowView drv,Label lblId)
        {
            string redirectUrl = string.Empty;
            redirectUrl = SPContext.Current.Site.ServerRelativeUrl + "" + "SystemSettings/RoleMgrDetails.aspx?Id=" + lblId.Text;

            link.HRef = redirectUrl;
            linkApp.Attributes.Add("href", redirectUrl);
        }
    }
}
